package cn.tedu.csms.employee.controller;

import cn.tedu.csms.base.response.JsonResult;
import cn.tedu.csms.employee.pojo.dto.EmployeeQuery;
import cn.tedu.csms.employee.pojo.dto.EmployeeSaveParam;
import cn.tedu.csms.employee.pojo.vo.EmployeeVO;
import cn.tedu.csms.employee.service.IEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "员工个人信息板块")
@Slf4j
@RestController
@RequestMapping("/v1/employee")
public class EmployeeController {

    @Autowired
    IEmployeeService employeeService;

    @ApiOperation("查询员工接口")
    @GetMapping("/select")
    public JsonResult select(EmployeeQuery employeeQuery){
        log.debug("查询员工:参数={}",employeeQuery);
        List<EmployeeVO> employeeVOList = employeeService.select(employeeQuery);
        return JsonResult.ok(employeeVOList);
    }

    @ApiOperation("新增员工接口")
    @PostMapping("/save")
    public JsonResult save(EmployeeSaveParam employeeSaveParam){
        log.debug("保存员工:参数={}",employeeSaveParam);
        employeeService.save(employeeSaveParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除员工接口")
    @PostMapping("/delete")
    public JsonResult delete(Long id){
        log.debug("删除员工:参数={}",id);
        employeeService.delete(id);
        return JsonResult.ok();
    }
}
